<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>药品信息</title>
    <!--    media="all"：这个CSS在所有页面都可以使用-->
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/static/admin/style.css}" media="all">
</head>
<body class="layui-layout-body">
<!--自适应宽度-->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px">
            <form class="layui-form layui-form-pane" action="">
                <!-- 判断是否是修改，如果是修改，需要传入的对象-->
                <input name="id" th:value="${obj?.id}" class="layui-input layui-hide">
<!--                拿到药品名称-->
                <div class="layui-form-item">
                    <label class="layui-form-label">药品名称</label>
                    <div class="layui-input-block">
<!--                     th:value="${obj?.name}"：判断是否是空值，如果是，拿到名称   lay-verify="required":必填 autocomplete="off":是否自动填入，否-->
                        <input type="text" name="name" th:value="${obj?.name}" lay-verify="required" placeholder="请输入药品名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">药品编码</label>
                    <div class="layui-input-block">
                        <input type="text" name="number" th:value="${obj?.number}" lay-verify="required" placeholder="请输入药品编码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">供应商</label>
                    <div class="layui-input-block">
<!--                        <input type="text" name="supplier" th:value="${obj?.supplier}" lay-verify="required" placeholder="请输入药品供应商" autocomplete="off" class="layui-input">-->
                        <select name="supplier" id="supplier"></select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">生产时间</label>
                    <div class="layui-input-block">
                        <input type="text" readonly name="producttime" id="producttime" th:value="${obj?.producttimeStr}" lay-verify="required" placeholder="请输入生产时间" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">保质期(月)</label>
                    <div class="layui-input-block">
                        <input type="text" name="warrenty" th:value="${obj?.warrenty}" lay-verify="required" placeholder="请输入保质期(月)" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">价格</label>
                    <div class="layui-input-block">
                        <input type="text" name="price" th:value="${obj?.price}" lay-verify="required" placeholder="请输入价格" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">库存</label>
                    <div class="layui-input-block">
                        <input type="text" name="stock" th:value="${obj?.stock}" lay-verify="required" placeholder="请输入库存" autocomplete="off" class="layui-input">
                    </div>
                </div>
<!--                隐藏按钮，提交-->
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="LAY_front-submit" id="LAY_front-submit" value="确定">
                </div>
            </form>
        </div>
    </div>
</div>

<script th:src="@{/static/layui/layui.js}"></script>
<script>
    layui.use(['form','laydate'], function () {
        var $ = layui.$;
        var laydate = layui.laydate;
        var form = layui.form;

        // 支持日期控件
        laydate.render({
            // 得到时间控件
            elem:"#producttime",
            // 点击之后时间控件一直显示
            trigger:'click'
        });
        // 获取当前供应商的值
        var currentSupplier = '[[${obj?.supplier}]]'
        // 获取供应商列表
        $.ajax({
            url:'/supplier/supplierList',
            dataType:'json',
            type:'POST',
            cache:false,
            success:function (data){
                $('#supplier').prepend("<option value=''>请选择</option>"); // 第一个值
                //然后循环便利data里面的数据
                for (var i = 0; i<data.data.length; i++){
                    // 如果说当前的供应商=获取的数据   显示数据为被选择的数据
                    if (currentSupplier == data.data[i].name){
                        // 赋值
                        $('#supplier').append("<option selected value='"+data.data[i].name+"'>"+data.data[i].name+"</option>");
                    }else {
                        $('#supplier').append("<option value='"+data.data[i].name+"'>"+data.data[i].name+"</option>");
                    }
                }
                // 渲染下拉列表，把内容加载进去
                form.render();
            }
        });
    });
</script>
</body>
</html>